<template>
  <div class="info-recommend">
    <div class="info-recommend-title">精选好物</div>
    <div class="i-box">
      <div class="i-item" v-for="(item, index) in mydata" :key="index">

        <div class="i-item-img">
          <img @click="goInfo(item.action.path)" :src="`${item.image_url}`" alt="">
        </div>
        <div class="i-item-name">{{ item.name }}</div>
        <div class="i-item-price">
          <i>￥{{ item.price }}</i>
          <del v-if="item.price !== item.market_price">￥{{ item.market_price }}</del>
        </div>
      </div>
    </div>
    <el-backtop :right="30" :bottom="100" />
  </div>
</template>


<style scoped>
.i-box {
  margin: 10px auto;
  width: 94vw;
  border-radius: 10px;
  display: flex;
  justify-content: space-evenly;
  flex-wrap: wrap;
}

.info-recommend-title {
  color: rgb(0, 0, 0);
  font-size: 14px;
  font-weight: 500;
  margin-top: 10px;
  margin-left: 5vw;
}

.i-item {
  margin: 5px 0px;
  background-color: #fff;
  border-radius: 10px;
}

.i-item-img img {
  width: 160px;
}

.i-item-name {
  color: rgba(0, 0, 0, 0.9);
  font-size: 16px;
  line-height: 18.67px;
  width: 160px;
  height: 40px;
  padding-left: 10px;
  overflow: hidden;
}

.i-item-price i {
  color: rgba(0, 0, 0, 0.9);
  font-size: 17.3333px;
  padding-left: 5px
}

.i-item-price del {
  color: rgb(175, 175, 175);
  font-size: 12px;
  margin-bottom: 1px;
  margin-left: 3.33333px;
}
</style>

<script setup lang="ts">
import { getRecommend } from '../../api/info'
import { ref, onMounted } from 'vue'
import { useRoute, useRouter } from "vue-router";





const route = useRoute()
const router = useRouter()
const uid = ref(route.params.id)
const mydata = ref([])
const goInfo = (id: number) => {

  router.replace({
    name: 'info',
    params: {
      id: id
    }
  })
  setTimeout(() => {
    router.go(0)
  },200 );
}

const info = async () => {
  let data = await getRecommend(Number(uid.value))
  mydata.value = data.data.related_recommend.data

}

onMounted(() => {
  info()
})
</script>